package com.java.interfaces.exer1;

/**
 * @author luzhikun
 * @date 2020/12/6- 16:23
 */
public class Test {
    public static void main(String[] args) {
        // 多态   向上转型
        Animal animal = new Cat();
        animal.setAge(3);
        animal.setColor("白色");
        animal.setName("小黄");
        System.out.println("这只猫的名字是：" + animal.getName() + "这只猫的颜色是：" + animal.getColor() + "这只猫的年龄是：" + animal.getAge());
        animal.sleep();
        animal.eat();

        //如果想调用 猫中特有的方法必须要使用 向下转型并且要判断一下 （is a）的关系
        if (animal instanceof Cat) {
            Cat cat = (Cat) animal;
            cat.fly();
        }
        System.out.println("------------------------------");
        System.out.println("------------------------------");
        System.out.println("------------------------------");
        Animal animal1 = new JumpCat();

        animal1.setName("跳跳猫");
        animal1.setAge(10101001);
        animal1.setColor("银色");
        System.out.println("这只猫的姓名是：" + animal1.getName() + "这只猫的颜色是：" + animal1.getColor() + "这只猫的年龄是：" + animal1.getAge());
        animal1.eat();
        animal1.sleep();
        if (animal1 instanceof JumpCat) {
            JumpCat jumpCat = (JumpCat) animal1;
            jumpCat.fly();
            jumpCat.swim();
            jumpCat.jump();
        }

    }
}
